﻿using Entity.ERP.DTO.PurchaseOrder;
using Entity.ERP.View.PurchaseOrder;
using Entity.ERP.View.PurchaseOrderItem;
using Entity.ERP.View.SaleOrder;
using FrameWork.DataHelper;
using FrameWork.Request;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.ERP;

namespace AnQinManagermentBackendAPI.Controller.ERP
{
    /// <summary>
    /// 采购订单管理
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    [AllowAnonymous]
    public class PurchaseOrderController : ControllerBase
    {
        private readonly PurchaseOrderService _purchaseOrderService;

        public PurchaseOrderController(PurchaseOrderService purchaseOrderService)
        {
            _purchaseOrderService = purchaseOrderService;
        }

        /// <summary>
        /// 获取采购订单列表
        /// </summary>
        [HttpGet]
        [ProducesResponseType(typeof(PageResult<PurchaseOrderView>), 200)]
        public async Task<IActionResult> GetPurchaseOrderList([FromQuery] PurchaseOrderSearchDTO purchaseOrderSearchDTO)
        {
            var response = await _purchaseOrderService.GetPurchaseOrderList(purchaseOrderSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 获取采购订单子单列表
        /// </summary>
        [HttpGet("item")]
        [ProducesResponseType(typeof(PageResult<PurchaseOrderItemView>), 200)]
        public async Task<IActionResult> GetPurchaseOrderItemList([FromQuery] PurchaseOrderItemSearchDTO purchaseOrderItemSearchDTO)
        {
            var response = await _purchaseOrderService.GetPurchaseOrderItemList(purchaseOrderItemSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 采购订单源单列表
        /// </summary>
        [HttpGet("Source")]
        public async Task<IActionResult> GetPurchaseOrderSourceList([FromQuery] PurchaseOrderSourceSearchDTO model)
        {
            var response = await _purchaseOrderService.GetPurchaseOrderSourceList(model);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增采购订单
        /// </summary>
        [HttpPost]
        public async Task<IActionResult> AddPurchaseOrder([FromBody] PurchaseOrderAddDTO purchaseOrderAddDTO)
        {
            var response = await _purchaseOrderService.AddPurchaseOrder(purchaseOrderAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 编辑采购订单
        /// </summary>
        [HttpPut]
        public async Task<IActionResult> PutPurchaseOrder([FromBody] PurchaseOrderUpdateDTO purchaseOrderUpdateDTO)
        {
            var response = await _purchaseOrderService.PutPurchaseOrder(purchaseOrderUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除采购订单
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeletePurchaseOrder([FromQuery] string Id)
        {
            var response = await _purchaseOrderService.DeletePurchaseOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 审核通过采购订单
        /// </summary>
        [HttpPost("Pass")]
        public async Task<IActionResult> PassPurchaseOrder([FromQuery] string Id)
        {
            var response = await _purchaseOrderService.PassPurchaseOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 审核不通过采购订单
        /// </summary>
        [HttpPost("UnPass")]
        public async Task<IActionResult> UnPassPurchaseOrder([FromQuery] string Id)
        {
            var response = await _purchaseOrderService.UnPassPurchaseOrder(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 反审核采购订单
        /// </summary>
        [HttpPost("CancelPass")]
        public async Task<IActionResult> CancelPassPurchaseOrder([FromQuery] string Id)
        {
            var response = await _purchaseOrderService.CancelPassPurchaseOrder(Id);
            return StatusCode(response.Status, response);
        }
    }
}
